<%@ page language="java" pageEncoding="UTF-8" %>
<%@include file="../../common/taglib.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="${basePath}">
    <title>无标题文档</title>
    <link href="${basePath}/css/style.css" rel="stylesheet" type="text/css">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

    <script src="${basePath}/script/common.js"></script>
    <script type="text/javascript">
        function selectSuper(v) {
            var temp = document.getElementById(v);
            var all = document.getElementById(v.substring(0, 3));
            if (temp.checked) {
                all.checked = true;
            } else {
                var flag = 0;
                var boxes = document.getElementsByName("interest");
                for (var i = 0; i < boxes.length; i++) {
                    if (boxes[i].id.substring(0, 4) == v.substring(0, 4) && boxes[i].checked) {
                        flag = 1;
                        break;
                    }
                }
                if (flag == 0) {
                    all.checked = false;
                }
            }
        }

        function all1(v) {
            var temp = document.getElementById(v);
            var boxes = document.getElementsByName("interest");
            if (temp.checked) {
                //var es = roleForm['curRights'];
                for (var i = 0; i < boxes.length; i++) {
                    if (boxes[i].id.substring(0, 3) == v) {
                        boxes[i].checked = true;
                    }
                }
            } else {
                for (var i = 0; i < boxes.length; i++) {
                    if (boxes[i].id.substring(0, 3) == v) {
                        boxes[i].checked = false;
                    }
                }
            }
        }

        $(function () {
            $("#submit").click(function () {
                //序列表单    interest=1&interest=2&interest=3
                var frmParam = $("#rfrm").serialize();
                //var frmParam = $("#rfrm").serializeArray();

                /* for(var key in frmParam){
                    //alert(key+"----"+frmParam[key]);
                    var paramObj = frmParam[key]
                    for(var key2 in paramObj){
                        alert(key2+"----"+paramObj[key2]);
                    }
                } */
                //var frmParam = $("#rfrm").serializeObject();
                //console.log(frmParam);

                // $("#rfrm").s
                $.ajax({
                    type: "POST",
                    url: "${basePath}/role/updateRight",
                    data: frmParam,

                    dataType: "json",/*响应json格式的数据*/
                    success: function (msg) {
                        if (msg.code == 1) {
                            alert("更新成功！！！");
                        }
                    },
                    error: function () {
                        alert("请求失败");
                    }
                });
            });
        });
    </script>

</head>

<body>
<div class="page_title">分配角色权限</div>

<br/>
<form action="${basePath}/role/updateRight" method="post" id="rfrm">
    <input type="hidden" name="method" value="updateRight"/>
    <input
            type="hidden" name="roleId" value="${curRole.roleId }" id="rId"/>
    <table class="data_list_table">
        <tr>
            <th>
                <div align="left">权限分配（选定后保存）当前角色-》${curRole.roleName }</div>
            </th>
        </tr>

        <c:forEach items="${rightList}" var="r" varStatus="index">
            <c:if test="${ r.rightType  eq 'Folder'}">
                <c:if test="${index.index ne 0 }">
                    </p>
                    </div>
                    </td>
                    </tr>
                    <tr height="4"></tr>
                </c:if>
                <tr>
                <td class="list_data_number">
                <div align="left">
                <p>
                    <input type="checkbox" id="${r.rightCode}" value="${r.rightCode}" name="interest"
                           <c:if test="${r.isSelected  eq 1 }">checked='checked'</c:if>
                           onclick="all1('${r.rightCode}')"/> <SPAN class=node>${r.rightText}</SPAN>
                </p>
                <p>

            </c:if>
            <c:if test="${ r.rightType  ne 'Folder'}">
                <input type="checkbox" value="${r.rightCode}" name="interest" id="${r.rightCode}"
                       <c:if test="${r.isSelected  eq 1 }">checked='checked'</c:if>
                       onclick="selectSuper('${r.rightCode}')"/> <SPAN class=node>${r.rightText}</SPAN>
            </c:if>
        </c:forEach>
        <tr height="4"></tr>
        <tr>
            <td class="list_data_number"><input id="submit" type="button" value="提交">&nbsp;&nbsp;
                <input type="button" value="返回" onclick="window.location.reload();">
            </td>
        </tr>
        <tr height="4"></tr>
    </table>
</form>


</body>
</html>
